<?php

require_once __DIR__ . '/support/bootstrap.php';

use app\model\CompanyKfModel;
use app\model\CompanyModel;

echo "=== 单位客服管理功能测试 ===\n\n";

try {
    // 1. 测试创建客服
    echo "1. 测试创建客服...\n";
    $kf = new CompanyKfModel();
    $kf->realname = '测试客服';
    $kf->phone = '13800138000';
    $kf->company_ids = '@1@2@';
    $kf->status = 1;
    $kf->created_at = time();
    $kf->updated_at = time();
    
    if ($kf->save()) {
        echo "✓ 客服创建成功，ID: " . $kf->id . "\n";
    } else {
        echo "✗ 客服创建失败\n";
    }
    
    // 2. 测试查询客服列表
    echo "\n2. 测试查询客服列表...\n";
    $kfList = CompanyKfModel::whereNull('deleted_at')->get();
    echo "✓ 找到 " . count($kfList) . " 个客服\n";
    
    foreach ($kfList as $item) {
        echo "  - ID: {$item->id}, 姓名: {$item->realname}, 电话: {$item->phone}\n";
    }
    
    // 3. 测试软删除
    echo "\n3. 测试软删除...\n";
    if ($kf->softDelete()) {
        echo "✓ 软删除成功\n";
    } else {
        echo "✗ 软删除失败\n";
    }
    
    // 4. 验证软删除后查询不到
    $deletedKf = CompanyKfModel::whereNull('deleted_at')->where('id', $kf->id)->first();
    if (!$deletedKf) {
        echo "✓ 软删除后查询不到记录\n";
    } else {
        echo "✗ 软删除后仍能查询到记录\n";
    }
    
    echo "\n=== 测试完成 ===\n";
    
} catch (Exception $e) {
    echo "✗ 测试失败: " . $e->getMessage() . "\n";
} 